<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Acknowledges consumption of a message</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="stomp.abort.html">« Stomp::abort</a></li>
      <li style="float: right;"><a href="stomp.begin.html">Stomp::begin »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.stomp.html">Stomp</a></li>
    <li>Acknowledges consumption of a message</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="stomp.ack" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Stomp::ack</h1>
  <h1 class="refname">stomp_ack</h1>
  <p class="verinfo">(PECL stomp &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Stomp::ack</span> -- <span class="refname">stomp_ack</span> &mdash; <span class="dc-title">Acknowledges consumption of a message</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-stomp.ack-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格 (method):</p>
   <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Stomp::ack</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$msg</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$headers</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">过程化风格:</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>stomp_ack</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$link</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$msg</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$headers</code><span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Acknowledges consumption of a message from a subscription using client acknowledgment.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-stomp.ack-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    <dt>
<code class="parameter">link</code></dt>
<dd>
<p class="para">仅对过程化样式：由 <span class="function"><a href="stomp.construct.html" class="function">stomp_connect()</a></span> 返回的 stomp 连接标识符。</p></dd>

    
     <dt>
<code class="parameter">msg</code></dt>

     <dd>

      <p class="para">
       The message/messageId to be acknowledged.       
      </p>
     </dd>

    
    <dt>
<code class="parameter">headers</code></dt>
<dd>
<p class="para">关联数组包含附加的头信息（例如： receipt）。</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-stomp.ack-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-stomp.ack-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4543">
    <p><strong>示例 #1 面向对象风格</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$queue&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'/queue/foo'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$msg&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;connection&nbsp;*/<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stomp&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Stomp</span><span style="color: #007700">(</span><span style="color: #DD0000">'tcp://localhost:61613'</span><span style="color: #007700">);<br />}&nbsp;catch(</span><span style="color: #0000BB">StompException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Connection&nbsp;failed:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;send&nbsp;a&nbsp;message&nbsp;to&nbsp;the&nbsp;queue&nbsp;'foo'&nbsp;*/<br /></span><span style="color: #0000BB">$stomp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #0000BB">$queue</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;subscribe&nbsp;to&nbsp;messages&nbsp;from&nbsp;the&nbsp;queue&nbsp;'foo'&nbsp;*/<br /></span><span style="color: #0000BB">$stomp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">subscribe</span><span style="color: #007700">(</span><span style="color: #0000BB">$queue</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;read&nbsp;a&nbsp;frame&nbsp;*/<br /></span><span style="color: #0000BB">$frame&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$stomp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">readFrame</span><span style="color: #007700">();<br /><br />if&nbsp;(</span><span style="color: #0000BB">$frame</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">body&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;acknowledge&nbsp;that&nbsp;the&nbsp;frame&nbsp;was&nbsp;received&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stomp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ack</span><span style="color: #007700">(</span><span style="color: #0000BB">$frame</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;remove&nbsp;the&nbsp;subscription&nbsp;*/<br /></span><span style="color: #0000BB">$stomp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">unsubscribe</span><span style="color: #007700">(</span><span style="color: #0000BB">$queue</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;connection&nbsp;*/<br /></span><span style="color: #007700">unset(</span><span style="color: #0000BB">$stomp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4544">
    <p><strong>示例 #2 过程化风格</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$queue&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'/queue/foo'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$msg&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stomp_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'ssl://localhost:61612'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;check&nbsp;connection&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Connection&nbsp;failed:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">stomp_connect_error</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;begin&nbsp;a&nbsp;transaction&nbsp;*/<br /></span><span style="color: #0000BB">stomp_begin</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'t1'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;send&nbsp;a&nbsp;message&nbsp;to&nbsp;the&nbsp;queue&nbsp;'foo'&nbsp;*/<br /></span><span style="color: #0000BB">stomp_send</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'transaction'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'t1'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;commit&nbsp;a&nbsp;transaction&nbsp;*/<br /></span><span style="color: #0000BB">stomp_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'t1'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;subscribe&nbsp;to&nbsp;messages&nbsp;from&nbsp;the&nbsp;queue&nbsp;'foo'&nbsp;*/<br /></span><span style="color: #0000BB">stomp_subscribe</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;read&nbsp;a&nbsp;frame&nbsp;*/<br /></span><span style="color: #0000BB">$frame&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stomp_read_frame</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$frame</span><span style="color: #007700">[</span><span style="color: #DD0000">'body'</span><span style="color: #007700">]&nbsp;===&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;acknowledge&nbsp;that&nbsp;the&nbsp;frame&nbsp;was&nbsp;received&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">stomp_ack</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$frame</span><span style="color: #007700">[</span><span style="color: #DD0000">'headers'</span><span style="color: #007700">][</span><span style="color: #DD0000">'message-id'</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;remove&nbsp;the&nbsp;subscription&nbsp;*/<br /></span><span style="color: #0000BB">stomp_unsubscribe</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$queue</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;close&nbsp;connection&nbsp;*/<br /></span><span style="color: #0000BB">stomp_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-stomp.ack-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <p class="para">A transaction header may be specified, indicating that the message acknowledgment should be part of the named transaction.</p></p></blockquote>
  <div class="tip"><strong class="tip">小技巧</strong><p class="simpara">Stomp is inherently asynchronous. Synchronous communication can be implemented adding a receipt header. This will cause methods to not return anything until the server has acknowledged receipt of the message or until read timeout was reached.</p></div>
 </div>


</div></div></div></body></html>